package engine.ui.chat
{
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	
	import newx.NxSprite;
	import newx.com.ResManager;
	import newx.com.config.StaticIni;
	import newx.com.control.text.NxLabel;
	
	public class ChatButton extends NxSprite
	{
		private var _skin		:String	=	"";
		private var _btnName	:String	=	"";
		
		//容器
		private var _activeSpace		:Sprite;
		private var _disActiveSpace	:Sprite;
		private var _displaySpace		:MovieClip;
		private var _btnLabel			:NxLabel;
		
		//数据
		private var _selected			:Boolean	=	true;
		private var _clickable			:Boolean	=	true;
		private var _type				:int		=	-1;
		private var _btnStr			:String		=	"";
		
		public function ChatButton(str:String,skin:String="",clickable:Boolean=true,type:int=-1)
		{
			_skin		=	skin;
			_clickable	=	clickable;
			_type		=	type;
			_btnStr		=	str;
			super();
			initGUI();
			buttonMode	=	true;
		}
		private function initGUI():void
		{
			if(_skin!="")
			{
				_displaySpace	=	ResManager.newResClass(_skin) as MovieClip;
				_displaySpace.gotoAndStop(1);
			}
			addChild(_displaySpace);
			_displaySpace.width	+= 6;
			
			_btnLabel			=	new NxLabel();
			_btnLabel.color		=	0xf2cb8c;
			_btnLabel.htmlStrByBorder	=	_btnStr;
			addChild(_btnLabel);
			
			_btnLabel.x	=	(width-_btnLabel.width)/2 - 2;
			_btnLabel.y	=	(height-_btnLabel.height)/2;
			
			//添加事件
			addEventListener(MouseEvent.CLICK, toggleSelect);
			addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
			addEventListener(MouseEvent.MOUSE_OUT, onMouseOut);
		}
		
		
		public function onMouseOver(e:MouseEvent):void
		{
			if(_btnLabel.text == StaticIni.getSwfLangStr("UIStr_1000894"))//"求助"
			{
				return;
			}
			_displaySpace.gotoAndStop(2);
		}
		
		public function onMouseOut(e:MouseEvent):void
		{
//			if(!_selected) return;
			_displaySpace.gotoAndStop(1);
		}
		
		public function toggleSelect(e:MouseEvent):void
		{
			
			if(!_clickable ||_btnLabel.text ==StaticIni.getSwfLangStr("UIStr_1000894"))//"求助"
			{
				return;
			}
			_displaySpace.gotoAndStop(2);
//			if(selected)
//			{
//				selected	=	false;
//				_btnLabel.color		=	0x9f9f9f;
//				_btnLabel.htmlText	=	_btnStr;
//			}else
//			{
//				selected	=	true;
				_btnLabel.color		=	0xf2cb8c;
				_btnLabel.htmlStrByBorder	=	_btnStr;
//			}
		}

		public function get selected():Boolean
		{
			return _selected;
		}

		public function set selected(value:Boolean):void
		{
			_selected = value;
//			if(_selected)
//			{
				_displaySpace.gotoAndStop(1);
//			}else
//			{
//				_displaySpace.gotoAndStop(3);
//			}
		}

		public function get label():String
		{
			return _btnStr;
		}
		public function get type():int
		{
			return _type;
		}

		public function set type(value:int):void
		{
			_type = value;
		}


	}
}